package com.hubiao.basics.thread.pool;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Description  创建线程池
 *
 * @author hubiao
 * @since 2021-01-18 14:39
 */
public class ThreadPoolExecutorDemo {

    /*** 可用处理器的Java虚拟机的CPU数量 */
    private static final int availableProcessor = Runtime.getRuntime().availableProcessors();

    public static void main(String[] args) {
        /*** 核心线程数 */
        int corePoolSize = availableProcessor * 2 + 1;
        /*** 最大线程数 */
        int maxPoolSize = (availableProcessor * 2 + 1) * 2;
        System.out.println( "可用处理器的Java虚拟机的CPU数量:" + availableProcessor + ";核心线程数:" + corePoolSize + ";最大线程数:" + maxPoolSize );

        ThreadPoolExecutor service = new ThreadPoolExecutor( corePoolSize, maxPoolSize,
                15L, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>( 1024 ),
                new ThreadPoolExecutor.AbortPolicy() );
    }
}
